package com.czk.model.proxy.dynamincproxy.practice;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * 代理类
 * @Author:ChenZhangKun
 * @Date: 2020/9/24 22:38
 */
public class ProxyLove  {
    private Object targetObject;
    public ProxyLove(Object targetObject){
       this.targetObject=targetObject;
    }
    public Object getProxyObject(){
        Object obj=Proxy.newProxyInstance(targetObject.getClass().getClassLoader(), targetObject.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("czk");
                method.invoke(targetObject,args) ;
                System.out.println("nzq");
                return proxy;
            }
        });
        return obj;
    }
}
